package com.service.uai.engine.pack;

import java.io.UnsupportedEncodingException;

import com.bpms.common.CommonUtil;
import com.bpms.common.Tools;
import com.bpms.common.VO;
import com.bpms.eai.IPackage;
import com.bpms.eai.PackTool;

public class ATMClientPack extends PackTool implements IPackage{

	public VO parseBuffer(byte[] buffer) {
		VO v=new VO();
		v.setAttr("result", new String(buffer));
		CommonUtil.debug("ATMClientPack-parseBuffer:"+v.getAttr("result"));
		return v;
	}

	public byte[] prepareBuffer(String svname, VO args) {
//		StringBuffer sb=new StringBuffer();
		StringBuffer msg=new StringBuffer();
		try {
				StringBuffer buf=new StringBuffer();
//				fieldpack(buf, "1001", "111111");//设备号//				fieldpack(buf, "1002", "2222221");//网点号//				fieldpack(buf, "1003", "11155");//认证码//				fieldpack(buf, "1004", "02");//
//				fieldpack(buf, "1005", Tools.getDate());//业务类型
//				fieldpack(buf, "1006", Tools.getTime());//发起网点号//				fieldpack(buf, "1007", "2222222");//收款人开户行
//				fieldpack(buf, "1008", "88888");//付款人开户行
//				fieldpack(buf, "1009", "543246787756");//收付款标志//				fieldpack(buf, "1010", "20120101");//持票人类型//				fieldpack(buf, "1011",  "20120501");//身份证号码//				fieldpack(buf, "1012", "1");//身份证姓名//				fieldpack(buf, "1013", "22.00");//是否支付密码
//				fieldpack(buf, "1014", "02291012387");//联系电话
//				fieldpack(buf, "1015", "");
				
				fieldpack(buf, "1001", "111111");//设备号
				fieldpack(buf, "1002", "2222221");//网点号
				fieldpack(buf, "1003", "11155");//认证码
				fieldpack(buf, "1004", "02");//
				fieldpack(buf, "1005", Tools.getDate());//业务类型
				fieldpack(buf, "1006", Tools.getTime());//发起网点号
				fieldpack(buf, "1007", "2222222");//收款人开户行
				fieldpack(buf, "1008", "88888");//付款人开户行
				fieldpack(buf, "1009", "543246787756");//收付款标志
				fieldpack(buf, "1010", "20120101");//持票人类型
				
				
				String body=buf.toString();
				String instanceid="00000000";
//				String transcode="2001";
				String transcode="2002";
				String answer="0000";
				String wholeLen=addleft0(String.valueOf(body.getBytes().length), 8);
				//本报文长度（不包括自身长度）+流水号+整个交易报文长度
				int bodylen=body.getBytes().length+instanceid.getBytes().length+
				wholeLen.getBytes().length+transcode.getBytes().length+
							answer.getBytes().length;
				String strLen=addleft0(String.valueOf(bodylen), 8);
				msg.append(strLen);
				msg.append(instanceid);
				msg.append(wholeLen);
				msg.append(transcode);
				msg.append(answer);
				msg.append(body);
				byte[] r=null;
				
				String msg1="00000234000000000000021020010000000000061001050131000000071002111111100000005100312345000000021004070000000810052012050800000006100614125000000008100700000001000000191009955339903007416021400000008101020120501000000081011201205080000000110121";
				
				r = msg1.getBytes("gb2312");
				return r;
			} catch (UnsupportedEncodingException e) {
				// TODO Auto-generated catch block
				CommonUtil.debug("ATMClientPack.sendBuffer exception",e);
				return null;
			}
//			return r;
			
		
		
	}

}
